package com.atguigu.order.controller;


import com.atguigu.order.bean.Order;
import com.atguigu.order.config.OrderConfig;
import com.atguigu.order.properties.OrderProperties;
import com.atguigu.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Collections;
//自动刷新功能
//@RefreshScope
@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private OrderProperties orderProperties;

//    @Value("${order.timeout}")
//    String orderTimeout;
//    @Value("${order.auto-confirm}")
//    String orderAutoConfirm;

    @GetMapping("/config")
    public String config(){
        return "oederTimeout = " + orderProperties.getTimeout() +
                ", orderAutoConfirm = " + orderProperties.getAutoConfirm() +
                ", orderDbUrl = " + orderProperties.getDbUrl();
    }

    @GetMapping("/create")
    public Order creatOrder(@RequestParam("userId") Long userId,@RequestParam("productId") Long id) {
        return orderService.creatOrder(userId, id);
    }
}
